package com.example.imoocmusicdemo.activities;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.StringUtils;
import com.example.imoocmusicdemo.R;
import com.example.imoocmusicdemo.utils.UserUtils;
import com.example.imoocmusicdemo.views.InputView;

public class RegisterActivity extends BaseActivity {

    private InputView mInputPhone,mInputPassword,mInputPasswordConfirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        
        initView();
    }

    /**
     * 初始化View
     * */
    private void initView() {
        initNavBar(true,"注册",false);

        mInputPhone = fd(R.id.input_phone);
        mInputPassword = fd(R.id.input_password);
        mInputPasswordConfirm = fd(R.id.input_password_confirm);
    }

    /**
     * 注册按钮点击事件
     * 1.用户输入合法性验证
     *      （1）用户输入手机号是否合法
     *      （2）用户是否输入和确定了密码
     *      （3）是否输入了已被注册的手机号
     * 2.保存用户输入的手机号和密码（MD5加密密码）
     * */
    public void onRegisterClick(View v){
        String phone = mInputPhone.getInputStr();
        String password = mInputPassword.getInputStr();
        String passwordConfirm = mInputPasswordConfirm.getInputStr();

        boolean result =  UserUtils.registerUser(this,phone,password,passwordConfirm);

        if(!result) return;

        //后退页面
        onBackPressed();
    }

}
